package com.wjboot.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.wjboot.common.util.R;
import com.wjboot.common.base.domain.system.SysDept;
import com.wjboot.system.service.SysDeptService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @description: 部门管理
 * @author: 周振林
 * @date: 2022-04-12
 * @Copyright: 博客：http://www.zhouzhenlin.com - 沉淀、分享、成长、让自己和他人都有所收获
 **/

@RestController
@RequestMapping("/api/sys/dept")
@Tag(name = "部门管理")
public class SysDeptController {

    @Autowired
    private SysDeptService sysDeptService;


    @GetMapping("/tree")
    @SaCheckPermission("sys_dept_view")
    @Operation(summary = "部门树")
    public R tree(String name){
        return R.ok(sysDeptService.tree(name));
    }

    @GetMapping("/{id}")
    @Operation(summary = "部门详情")
    public R getById(@PathVariable Integer id){
        return R.ok(sysDeptService.getById(id));
    }

    @PostMapping
    @SaCheckPermission("sys_dept_add")
    @Operation(summary = "部门添加")
    public R save(@RequestBody SysDept sysDept){
        return R.ok(sysDeptService.saveDept(sysDept));
    }

    @PutMapping
    @SaCheckPermission("sys_dept_edit")
    @Operation(summary = "部门编辑")
    public R update(@RequestBody SysDept sysDept){
        return R.ok(sysDeptService.updateDept(sysDept));
    }

    @DeleteMapping("/{id}")
    @SaCheckPermission("sys_dept_del")
    @Operation(summary = "部门删除")
    public R deleteById(@PathVariable Integer id){
        return R.ok(sysDeptService.removeDeptById(id));
    }

}
